package me.militch.quickcore.mvp.presenter;

import android.app.Activity;

import java.lang.reflect.Type;
import java.util.Arrays;

import me.militch.quickcore.mvp.IPresenter;

public class Presenter implements IPresenter {
    protected Activity activity;
    public Presenter(Activity activity){
        this.activity = activity;
    }
    @Override
    @SuppressWarnings("unchecked")
    public  <T> T view(Class<T> tClass){
        T t = null;
        //判断指定的类是否为目标类所实现的接口
        Type[] types = activity.getClass().getGenericInterfaces();
        boolean exists = Arrays.asList(types).contains(tClass);
        if(exists){
            t = (T) activity;
        }
        return t;
    }
    @Override
    public void detachView(){
        this.activity = null;
    }
}
